function res = osl_correct_meeg_paths(D,path)
% Corrects hidden hard-coded paths in spm object to those in D.path or
% to a specified path.

if nargin > 1
    D = path(D,path);
end


Ds = struct(D);

Ds.data.y.fname = fullfile(D.path,D.fnamedat);

D = Ds;

save(fullfile(D.path,D.fname),'D');
res = spm_eeg_load(fullfile(D.path,D.fname));
    
end